import Cesium from '../../Ces/Cesium'

export default (text) => {
  var lines = text.split('\n')

  const headerInfo = lines[1].split(' ')
  const west = Number(headerInfo[8])
  const east = Number(headerInfo[9])
  const south = Number(headerInfo[11])
  const north = Number(headerInfo[10])
  const width = Number(headerInfo[12])
  const height = Number(headerInfo[13])

  const arrayBufferView = new Float32Array(width * height)

  let offset = 0
  for (let i = 2; i < lines.length; i++) {
    const values = lines[i].split('   ')
    values.forEach(e => {
      if (e !== '')
        arrayBufferView[offset++] = Number(e)
    })
  }

  return {
    source: {
      width,
      height,
      arrayBufferView,
      pixelFormat: Cesium.PixelFormat.R,
      pixelDatatype: Cesium.PixelDatatype.FLOAT,
    },
    west,
    south,
    east,
    north,
  }
}
